package com.geeklan.smart.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.geeklan.smart.R;

public class DialogUtils {
    public static void showSelectDialog(Context context, View.OnClickListener gllaryOnClickListener, View.OnClickListener cameraOnClickListener) {
        Dialog bottomDialog = new Dialog(context, R.style.BottomDialog);//自定义样式
        View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_bottom_picture, null);
        bottomDialog.setContentView(contentView);
        Button choosePhoto = (Button) contentView.findViewById(R.id.picture_gllary);
        Button takePhoto = (Button) contentView.findViewById(R.id.picture_camera);
        TextView cancel = (TextView) contentView.findViewById(R.id.picture_cancle);
        choosePhoto.setOnClickListener(v -> {
            bottomDialog.dismiss();
            gllaryOnClickListener.onClick(v);
        });
        takePhoto.setOnClickListener(v -> {
            bottomDialog.dismiss();
            cameraOnClickListener.onClick(v);
        });
        cancel.setOnClickListener(v -> bottomDialog.dismiss());

        //<editor-fold desc="距离下，左右边框距离，根据需求可删除或者增大">
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();
        params.width = context.getResources().getDisplayMetrics().widthPixels - DensityUtils.dpToPx(context, context.getResources().getDimension(com.smart.base.R.dimen.dp_16));
        params.bottomMargin = DensityUtils.dpToPx(context, context.getResources().getDimension(com.smart.base.R.dimen.dp_10));
        contentView.setLayoutParams(params);
        //</editor-fold>

        bottomDialog.setCanceledOnTouchOutside(true);
        bottomDialog.getWindow().setGravity(Gravity.BOTTOM);
        bottomDialog.show();
    }
}
